package health_system.health_system.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;

/**
 * Netty聊天服务器关闭监听器
 * 在Spring应用关闭时确保Netty聊天WebSocket服务器正确关闭
 */
@Component
public class NettyChatMessageServerShutdownListener implements ApplicationListener<ContextClosedEvent> {
    private static final Logger logger = Logger.getLogger(NettyChatMessageServerShutdownListener.class.getName());
    
    @Autowired
    private NettyChatMessageServerConfig nettyChatMessageServerConfig;
    
    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        logger.info("应用程序关闭，正在关闭Netty聊天WebSocket服务器...");
        nettyChatMessageServerConfig.shutdown();
    }
} 